<?php
class Currency extends CurrencyPeer
{
	function Currency()
	{
		parent::CurrencyPeer();
	}
	
	public static function getAllCurrencies($active=1, $orderby='id', $limit=NULL)
	{
		$database = new Database();
		if ($active != 1)
			$active = 0;
		$query = "SELECT id FROM Currency WHERE status = $active ORDER BY $orderby ";
		$result = $database->query($query);
		$ids = $database->fetch_array($result);
		$currencies = array();
		foreach ($ids as $id) {
			$t = new Currency();
			$t->select($id['id']);
			$currencies[] = $t;
		}
		return $currencies;
	}
	
	function getCurrencyByCode($code)
	{
		$currency = null;
		$database = new Database();
		$query = "SELECT id FROM Currency WHERE currency_code = $code LIMIT 1";
		$result = $database->query($query);
		$ids = $database->fetch_array($result);
		foreach ($ids as $id) {
			$currency = new Currency();
			$currency->select($id['id']);
		}
		return $currency;
	}
	
	public static function getCode($currency_id)
	{
		$db = new Database();
		$query = "SELECT currency_code FROM currency WHERE id = '".$currency_id."'";
		$result = $db->query($query);
		$row = $db->fetch_array($result);
		return $row[0]['currency_code'];
	}
	
	function getVND($money)
	{
		$vnd = $money*$this->getSell();
		return $vnd;
	}
}
?>